package com.lucifer.cloud.boot.blog.domin.type;

import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author lucifer
 * @date 2024/1/16 16:05
 */
@Getter
public enum BlogStatusType {

    UPLOAD(1,"UPLOAD","待审核"),
    APPROVE(2,"APPROVE","审核通过"),
    REJECT(3,"REJECT","未通过审核"),
    OPEN(4,"OPEN","公开");

    private final Integer index;

    private final String code;

    private final String name;

    private static final Map<Integer, BlogStatusType> INDEX_MAPPING = Collections.unmodifiableMap(
            Arrays.stream(BlogStatusType.values()).collect(Collectors.toMap(BlogStatusType::getIndex, Function.identity()))
    );

    @NotNull
    public static Optional<BlogStatusType> indexOf(@Nullable Integer index) {
        return Optional.ofNullable(index).map(INDEX_MAPPING::get);
    }


    BlogStatusType(@NotNull Integer index, @NotNull String code, @NotNull String name) {
        this.index = index;
        this.code = code;
        this.name = name;
    }


}
